package com.itheima.Demo;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.AsynchronousServerSocketChannel;
import java.nio.channels.AsynchronousSocketChannel;
import java.nio.channels.CompletionHandler;

public class Demo异步非阻塞连接 {
    public static void main(String[] args) throws IOException {
        //创建对象
        AsynchronousServerSocketChannel assc = AsynchronousServerSocketChannel.open();
        //绑定端口
        assc.bind(new InetSocketAddress(10101));
        //获取客户端连接
        //异步非阻塞的方法
        assc.accept(null, new CompletionHandler<AsynchronousSocketChannel, Object>() {
            @Override
            public void completed(AsynchronousSocketChannel asynchronousSocketChannel, Object o) {
                //回调函数,回调方法;
            }

            @Override
            public void failed(Throwable throwable, Object o) {

            }
        });
    }
}
